package com.cjm.algorithm.leetcode;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class IsIsomorphic205 {
    public static boolean isIsomorphic(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }

        char[] smap = new char[256];
        char[] tmap = new char[256];

        char[] sarr = s.toCharArray();
        char[] tarr = t.toCharArray();

        for (int i = 0;i < s.length();i++) {
            char sitem = sarr[i];
            char titem = tarr[i];

            if (smap[sitem] != 0 && smap[sitem] != titem) {
                return false;
            }
            if (tmap[titem] != 0 && tmap[titem] != sitem) {
                return false;
            }
            smap[sitem] = titem;
            tmap[titem] = sitem;

        }

        return true;
    }

    public static void main(String[] args) {
        System.err.println(isIsomorphic("egg", "add"));
        System.err.println(isIsomorphic("foo", "bar"));
        System.err.println(isIsomorphic("paper", "title"));
    }
}
